package org.aphelie.torg.ruler.internal.core.character;

import org.aphelie.torg.ruler.core.IIdentifiable;
import org.aphelie.torg.ruler.core.character.ICharacterObject;
import org.aphelie.torg.ruler.core.character.ISharedCharacterModel;
import org.eclipse.core.runtime.CoreException;


public abstract class IdentifiableCharacterObject extends CharacterObject implements IIdentifiable {

    private static final long serialVersionUID = 1L;
    protected String fID;

    public IdentifiableCharacterObject() {
    }

    public String getId() {
        return fID;
    }

    public void setId(String id) throws CoreException {
        ensureModelEditable();
        String oldValue = fID;
        fID = id;
        firePropertyChanged(K_ID, oldValue, id);
    }

    public void restoreProperty(String name, Object oldValue, Object newValue) throws CoreException {
        if (name.equals(K_ID)) {
            setId(newValue != null ? newValue.toString() : null);
            return;
        }
        super.restoreProperty(name, oldValue, newValue);
    }

    /* (non-Javadoc)
     * @see org.eclipse.pde.internal.core.plugin.CharacterObject#reconnect(org.eclipse.pde.core.plugin.ISharedCharacterModel, org.eclipse.pde.core.plugin.ICharacterObject)
     */
    public void reconnect(ISharedCharacterModel model, ICharacterObject parent) {
        super.reconnect(model, parent);
        // No transient fields
    }

}
